library(gridExtra)
library(readstata13)
library(ggplot2)
library(gridExtra)
library(foreign)
library(MASS)
library(Matrix)
library(lattice)
library(rdd)
library(foreign)
library(ri)
library(scales)

rm(list = ls())
# Set working directory. Please set your own
setwd("~/Desktop/PSRM Replication")



###################
#Figure 3, Panel B#
###################




data <- read.dta("Data/samealltogether.dta")

theme_base1 <- 
  theme_minimal(base_size=15)  + 
  theme(legend.position=c(0.1, .1),  legend.key.size = unit(1,"line"),
        axis.text=element_text(size=16),axis.title.x=element_text(size=14),axis.title.y=element_text(size=16),
        plot.title = element_text(size=16, hjust= 0.5))

data$grp<-as.factor(data$id3)





main<-ggplot(data, aes(x=id, y =estimate ,color=grp)) +   
  geom_point(size = 2,position=position_dodge(0.35)) +
  geom_errorbar(aes(ymax = max95, ymin = min95),width=0,  size=.7,position=position_dodge(width=0.35))+
  geom_errorbar(aes(ymax = max90, ymin = min90),width=0, size=1.6,position=position_dodge(width=0.35))+
  scale_color_manual(name="Election",labels=c("Presidential","Same-Type", "Midterm"),values=c("blue","black","red")) + 
  scale_y_continuous(limits = c(-.07, .15))+ 
  scale_x_continuous(name="Election Counter",breaks = c(2,3,4,5,6,7,8,9,10,11,12,13,14,15),limits=c(1.75,15.25))+
  geom_hline(yintercept = 0, 
             linetype = 2, color = "black")+ ylab("ITT of Same-Election Eligibles") + xlab("")+
  theme_base1 + ggtitle("Difference in Probability of Voting:\n Same vs different type of election") 
main
ggsave("Graphs/Alltogether15.pdf", width = 22, height = 18, units = "cm")  